﻿using Exceptionless;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Api.Catalog.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {

        private readonly ILogger<ValuesController> _logger;
        private IConfiguration _configuration;

        public ValuesController(ILogger<ValuesController> logger, IConfiguration configuration)
        {
            _logger = logger;
            _configuration = configuration;
        }


        //[Authorize]
        [HttpGet]
        public IEnumerable<string> Get()
        {
            Console.WriteLine($"{this._configuration["id"]}:{this._configuration["post"]} Get ");
            return new string[] { "Api.Catalog1", "Api.Catalog2",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") };
        }

        [HttpGet("{id}")]
        public IActionResult Get(int id)
        {
            Console.WriteLine($"{this._configuration["id"]}:{this._configuration["post"]} Get({id}) ");
            var res = new { id = 6005, name = "Calalog" };
            return new JsonResult(res);
        }

        /// <summary>
        /// 测试Exceptionless
        /// </summary>
        [HttpGet("gete")]
        public IActionResult GetE()
        {
            try
            {
                string str = null;
                str.ToString();
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
            }
            return Ok($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
        }

        [HttpGet("getok/{key}")]
        public IActionResult GetOK(string key)
        {
            var val = _configuration.GetValue<string>(key);
            return Ok($"ok-------------{val}");
        }

    }
}
